<?php
/**
 * Created by IntelliJ IDEA.
 * User: Kwesi
 * Date: 4/11/14
 * Time: 12:56 AM
 */
	include_once("adb.php");

	class community extends adb{
        function community(){
            adb::adb();
        }
        /**
         *query all communities in the table and store the dataset in $this->result
         *@return if successful true else false
         */

        function get_all_communities(){
            $query="select community_id, community_name, latitude, longitude, population, household from community";
            return $this->query($query);
        }

        function add_community($community_name,$latitude,$longitude, $population, $household){
            //write the SQL query and call $this->query()
            $query="insert into community set community_name='$community_name',
            latitude='$latitude' ,longitude='$longitude', population='$population',household='$household'";
            return $this->query($query);
        }

        /**
         *updates the record identified by id
         */
        function update_community($community_id,$community_name,$latitude,$longitude,$population,$household)
        {
            $query="update community set community_name='$community_name',
					latitude='$latitude',longitude='$longitude',population='$population',
					household='$household' where community_id='$community_id'";
            if(!$this->query($query))
            {
                return false;
            }
            return true;
        }

        function search_community($name)
        {
            $query = "select * from community where community_name like '%$name'";

            return $this -> query($query);

        }

        function delete_community($community_id)
        {
            $query = "delete from community where community_id='$community_id'";

            return $this -> query($query);
        }

        function get_community($id){
            $query="select * from community where community_id='$id'";
            if(!$this->query($query)){
                return false;
            }
            return $this->fetch();
        }
    }
?>